package blackstar.plugin.performance.stat;


/**
 * @author RayWoo (ayufox@gmail.com)
 * 
 */
public class SimpleStatItem
{
	private String className;
	private String methodName;
	private long totalTimeNano;// 总调用时间
	private long totalInvokes;// 总调用次数
	private long[] threadholdCounts;//阀值总数
	private ThreadHoldConfig threadHoldConfig;//阀值配置

	public SimpleStatItem(String className, String methodName,
			ThreadHoldConfig threadHoldConfig)
	{
		this.className = className;
		this.methodName = methodName;
		this.threadholdCounts = new long[threadHoldConfig.getThreadholdLength()];
		this.threadHoldConfig = threadHoldConfig;
	}

	public void add(long timeNano)
	{
		this.totalTimeNano += timeNano;
		this.totalInvokes++;
		this.threadholdCounts[threadHoldConfig.getThreadholdIndex(timeNano)]++;
	}

	public String getFullName()
	{
		return this.className + "." + this.methodName;
	}

	public String getClassName()
	{
		return className;
	}

	public String getMethodName()
	{
		return methodName;
	}

	public long getTotalTimeNano()
	{
		return totalTimeNano;
	}

	public long getTotalInvokes()
	{
		return totalInvokes;
	}

	public long getAvarageNano()
	{
		return (this.totalTimeNano / this.totalInvokes);
	}

	public long[] getThreadholdCounts()
	{
		return threadholdCounts;
	}

	public String toString()
	{
		StringBuilder builder = new StringBuilder(128);
		builder.append("SimpleStatItem[");
		builder.append("className=");
		builder.append(this.className);
		builder.append(",methodName=");
		builder.append(this.methodName);
		builder.append(",totalTimeNano=");
		builder.append(this.totalTimeNano);
		builder.append(",totalInvokes=");
		builder.append(this.totalInvokes);
		builder.append("]");
		return builder.toString();
	}
}
